﻿using FangChan.Common;
using McsWeb.Common;
using McsWeb.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Mvc;

namespace McsWeb.Controllers
{
    public class PumpWalletRunningsController : Controller
    {
        #region 列表
        public ActionResult Index()
        {  
            return View();
        }

        public string IndexAsync(string Name,string Address, int pageIndex, int pageSize)
        { 
            List<Result> result = new List<Result>();
              
            int total = Convert.ToInt32(FangChan.DBUtility.DbHelperSQL.GetSingle("select dbo.Fn_Value_PumpWalletRunningsCount('"+ Address + "')"));
            DataTable dt = FangChan.DBUtility.DbHelperSQL.Query("select * from dbo.Fn_Table_PumpWalletRunnings('" + Address + "'," + pageIndex + "," + pageSize + ")").Tables[0];
            foreach (DataRow item in dt.Rows)
            {
                Result r = new Result();
                r.ID = Convert.ToInt32(item["ID"]);
                r.BlockNumber = Convert.ToString(item["BlockNumber"]);
                r.TimeStamp = Convert.ToString(item["TimeStamp"]);
                r.Hash = Convert.ToString(item["Hash"]);
                r.From = Convert.ToString(item["From"]);
                r.To = Convert.ToString(item["To"]);
                r.Value = Convert.ToString(item["Value"]);
                r.GasPrice = Convert.ToString(item["GasPrice"]); 
                result.Add(r);
            } 

            GridData<Result> gridData = total > 0 ? new GridData<Result>() { total = total, rows = result } : new GridData<Result>() { total = total, rows = new List<Result>() };

            return gridData.ToJson();
        }
        #endregion

        public string GetAddress()
        {
            DataTable dt = FangChan.DBUtility.DbHelperSQL.Query("select ID,Address,Remark from PumpWallets").Tables[0];

            return dt.DataTable2Json();
        }
        
        public string TimestampToDateTime(string timestamp)
        {
            DateTime result = TimestampHelper.TimestampToDateTime(timestamp);
            return result.ToString("yyy-MM-dd HH:mm:ss"); 
        }

        public void PumpWalletAsync()
        {
            Tools.PumpWalletAsync();
        }
    }
}